﻿using FastReport;
//using FastReport.DevComponents.DotNetBar.Controls;
using Infragistics.Documents.Reports.Graphics;
using Kingdee.BOS.WebApi.Client;
using Kingdee.BOS.WebApi.DataEntify;
using NPOI.SS.Formula.Functions;
using Org.BouncyCastle.Bcpg;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Printing;
using System.IO;
using System.Linq;
using System.Security.Policy;
using System.Text;
using System.Threading.Tasks;
using System.Web.UI;
using System.Windows.Forms;

namespace biaoqian
{
    public partial class Production_TAB : Form
    {
        Class1 one = new Class1();
        LDhuoyunEntities db = new LDhuoyunEntities();

        public Production_TAB()
        {
            InitializeComponent();
        }

        private void Production_TAB_Load(object sender, EventArgs e)
        {
            qqq();
            //GET_CGDD();
            GET_GXJHLB();
            panel1.Visible = false;
            panel2.Visible = false;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            GET_GXJHLB();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string hang = textBox1.Text;
            DataTable dataTable = one.ERP_cgdd();
            if (hang == null)
            {
                MessageBox.Show("请先选择行号");

            }
            else
            {
                foreach(DataGridViewRow data in dataGridView1.Rows)
                {
                    string blbh = data.Cells[2].Value.ToString();
                    string gg = data.Cells[4].Value.ToString();
                    DateTime riqi2 = DateTime.Parse(data.Cells[5].Value.ToString());
                    string sl = data.Cells[3].Value.ToString();
                    string riqi = riqi2.ToString("yyyy-MM-dd");

                    if (data.Cells[0].Value.ToString() == hang)
                    {
                        string zjm = "";
                        string daobao = "";
                        string daobao2 = "";
                        string FName = "";
                        string F_land_MTSL = "";
                        DataTable wlxx = GET_WUliao(data.Cells[2].Value.ToString());
                        foreach(DataRow data1 in wlxx.Rows)
                        {
                            daobao = data1[0].ToString()+"PCS/扎";
                            daobao2 = data1[0].ToString();
                            zjm = data1[1].ToString();
                            FName = data1[2].ToString();
                            F_land_MTSL = data1[3].ToString();
                        }

                        if(zjm== "美普森"||zjm== "杰森客户")
                        {
                            string bz = GET_KHWLDY(blbh);
                            DataTable xbqm1 = one.XbiaoqM2();

                            
                            if (daobao2 == "0")
                            {
                                daobao2 = "1";
                            }
                            int Printtimes = int.Parse(sl) / int.Parse(daobao2) + 2;
                            string shur = textBox12.Text.Trim();
                            if (shur!=""|| shur != null)
                            {
                                daobao = shur;
                            }
                            xbqm1.Rows.Add(FName, blbh, gg, bz, daobao, riqi, Printtimes);

                            DataSet da = new DataSet();
                            da.Tables.Add(xbqm1);
                            xbqm1.TableName = "Table1";
                            //模板1
                            //string baseDirectory1 = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName;
                            string physicalPath1 = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Production label\\Small label(template2).frx");

                            Report report1 = new Report();
                            report1.Load(physicalPath1);//打开文件/*
                            report1.RegisterData(da);//绑定数据源
                                                     //webReport.Report.SetParameterValue("ksnfjidn", Appbian);//替换fastreport参数的值--
                            DataBand data1 = report1.Report.FindObject("Data1") as DataBand;
                            data1.DataSource = report1.Report.GetDataSource("Table1");
                            report1.PrintSettings.Copies = Printtimes;
                            report1.Prepare();
                            report1.ShowPrepared();


                            DataTable xbqm2 = one.XbiaoqM2_1();
                            int Printtimes2 = 1;
                            xbqm2.Rows.Add(FName, blbh, gg, bz,riqi, Printtimes);


                            DataSet da3 = new DataSet();
                            da3.Tables.Add(xbqm2);
                            xbqm1.TableName = "Table1";
                            //模板1
                            //string baseDirectory12 = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName;
                            string physicalPath12 = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Production label\\Small label2(template2).frx");

                            Report report12 = new Report();
                            report12.Load(physicalPath12);//打开文件/*
                            report12.RegisterData(da3);//绑定数据源
                                                       //webReport.Report.SetParameterValue("ksnfjidn", Appbian);//替换fastreport参数的值--
                            DataBand data12 = report12.Report.FindObject("Data1") as DataBand;
                            data12.DataSource = report12.Report.GetDataSource("Table1");
                            report12.PrintSettings.Copies = Printtimes2;
                            report12.Prepare();
                            report12.ShowPrepared();



                            string scry = textBox3.Text;
                            string rkrq = textBox6.Text;
                            string jyy = textBox2.Text;
                            string pd = textBox8.Text;
                            string ckrky = textBox7.Text;
                            string sl2 = textBox4.Text;
                            if (sl2 == null)
                            {
                                sl2 = sl;
                            }

                            DataTable dataTable2 = one.BiaoShi1();
                            dataTable2.Rows.Add(blbh, FName, gg, sl2, scry, rkrq, jyy, pd, ckrky);

                            DataSet da2 = new DataSet();
                            da2.Tables.Add(dataTable2);
                            dataTable2.TableName = "Table1";

                            string baseDirectory = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName;
                            
                            string physicalPath = System.IO.Path.Combine(baseDirectory, "Production label\\Identification card(1).frx");
                            Report report = new Report();
                            report.Load(physicalPath);//打开文件/*
                            report.RegisterData(da2);//绑定数据源
                                                    //webReport.Report.SetParameterValue("ksnfjidn", Appbian);//替换fastreport参数的值--
                            DataBand data3 = report.Report.FindObject("Data1") as DataBand;
                            data3.DataSource = report.Report.GetDataSource("Table1");
                            report.PrintSettings.Copies = Printtimes/2;
                            report.Prepare();
                            report.ShowPrepared();

                        }
                        else
                        {
                            DataTable xbqm1 = one.XbiaoqM1();
                            
                            if (daobao2 == "0")
                            {
                                daobao2 = "1";
                            }
                            int Printtimes = int.Parse(sl) / int.Parse(daobao2) + 2;
                            string shur = textBox12.Text.Trim();
                            if (shur != "" || shur != null)
                            {
                                daobao = shur;
                            }
                            xbqm1.Rows.Add(FName, blbh, gg, daobao, riqi, Printtimes);
                            
                            
                            int splitIndex = 9;
                            string firstPart = FName.Substring(0, splitIndex);
                            string secondPart = FName.Substring(splitIndex);

                            DataSet da = new DataSet();
                            da.Tables.Add(xbqm1);
                            xbqm1.TableName = "Table1";
                            //模板1
                            //string baseDirectory1 = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName;
                            string physicalPath1 = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Production label\\Small label(template1).frx");

                            Report report1 = new Report();
                            report1.Load(physicalPath1);//打开文件/*
                            report1.RegisterData(da);//绑定数据源
                                                     //webReport.Report.SetParameterValue("ksnfjidn", Appbian);//替换fastreport参数的值--
                            DataBand data1 = report1.Report.FindObject("Data1") as DataBand;
                            data1.DataSource = report1.Report.GetDataSource("Table1");
                            report1.PrintSettings.Copies = Printtimes;
                            report1.Prepare();
                            report1.ShowPrepared();


                            DataTable xbqm2 = one.XbiaoqM1_1();
                            int Printtimes2 = 1;
                            xbqm2.Rows.Add(FName, blbh, gg, riqi, Printtimes);


                            DataSet da3 = new DataSet();
                            da3.Tables.Add(xbqm2);
                            xbqm1.TableName = "Table1";
                            //模板1
                            //string baseDirectory12 = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName;
                            string physicalPath12 = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Production label\\Small label2(template1).frx");

                            Report report12 = new Report();
                            report12.Load(physicalPath12);//打开文件/*
                            report12.RegisterData(da3);//绑定数据源
                                                     //webReport.Report.SetParameterValue("ksnfjidn", Appbian);//替换fastreport参数的值--
                            DataBand data12 = report12.Report.FindObject("Data1") as DataBand;
                            data12.DataSource = report12.Report.GetDataSource("Table1");
                            report12.PrintSettings.Copies = Printtimes2;
                            report12.Prepare();
                            report12.ShowPrepared();


                            if (zjm == "百库")
                            {
                                DataTable dataTable1 = one.BiaoShi2();
                                string text1 = textBox5.Text;
                                string text2 = textBox11.Text;
                                string text3 = textBox9.Text;
                                string text4 = textBox10.Text;
                                if (text1 != null)
                                {
                                    firstPart = text3;
                                    
                                }
                                if (text2 != null)
                                {
                                    gg = text2;
                                }
                                if (text3 != null)
                                {
                                    secondPart = text1;
                                }
                                if (text4 != null)
                                {
                                    F_land_MTSL = text4;
                                }
                                dataTable1.Rows.Add(secondPart, gg, firstPart, F_land_MTSL);

                                DataSet da2 = new DataSet();
                                da2.Tables.Add(dataTable1);
                                dataTable1.TableName = "Table1";

                                //string baseDirectory = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName;
                                string physicalPath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Production label\\Identification Card 2.frx");
                                
                                Report report = new Report();
                                report.Load(physicalPath);//打开文件/*
                                report.RegisterData(da2);//绑定数据源
                                                        //webReport.Report.SetParameterValue("ksnfjidn", Appbian);//替换fastreport参数的值--
                                DataBand data3 = report.Report.FindObject("Data1") as DataBand;
                                data3.DataSource = report.Report.GetDataSource("Table1");
                                report.PrintSettings.Copies = Printtimes;
                                report.Prepare();
                                report.ShowPrepared();
                            }
                            else
                            {
                                string scry = textBox3.Text;
                                string rkrq = textBox6.Text;
                                string jyy = textBox2.Text;
                                string pd = textBox8.Text;
                                string ckrky = textBox7.Text;
                                string sl2 = textBox4.Text;
                                if (sl2 == null)
                                {
                                    sl2 = sl;
                                }
                                
                                DataTable dataTable2 = one.BiaoShi1();
                                dataTable2.Rows.Add(blbh, FName,gg, sl2, scry,rkrq,jyy,pd,ckrky);

                                DataSet da2 = new DataSet();
                                da2.Tables.Add(dataTable2);
                                dataTable2.TableName = "Table1";


                                //string baseDirectory = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName;
                                string physicalPath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Production label\\Identification card(1).frx");
                                Report report = new Report();
                                report.Load(physicalPath);//打开文件/*
                                report.RegisterData(da2);//绑定数据源
                                                        //webReport.Report.SetParameterValue("ksnfjidn", Appbian);//替换fastreport参数的值--
                                DataBand data3 = report.Report.FindObject("Data1") as DataBand;
                                data3.DataSource = report.Report.GetDataSource("Table1");
                                report.PrintSettings.Copies = Printtimes / 2;
                                report.Prepare();
                                report.ShowPrepared();
                            }
                        }
                        
                    }
                }
            }
            GET_GXJHLB();

        }

        private void comboBox1_KeyUp(object sender, KeyEventArgs e)
        {

        }
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
        private string GET_KHWLDY(string wlbm)
        {
            DateTime now = DateTime.Now;
            string currentDateTime = now.ToString("yyyy-MM-dd HH:mm:ss");
            K3CloudApi client = new K3CloudApi();
            //用于记录结果
            StringBuilder Info = new StringBuilder();
            //业务对象标识
            string formId = "SAL_CustMatMapping";
            //查询字段集合，即返回哪些数据，不能为空，根据不同业务单据填写不同的字段名，以下仅为示例
            string fieldKeys = "FCustMatName";
            //请求参数，示例使用的是SDK提供的模板类，还可以使用字符串拼接等方式
            var ZBLx = wlbm;
            var param = new QueryParam()
            {
                FormId = formId,
                FieldKeys = fieldKeys,
                FilterString = "FMaterialId.FNumber like'%" + ZBLx + "%'",
                TopRowCount = 0,
                StartRow = 0,
                Limit = 120,
                OrderString = "FMaterialId.FNumber",
            };
            //调用接口
            var result = client.ExecuteBillQuery(param.ToJson());
            if (dataGridView1.Columns.Count != 0)
            {
                dataGridView1.Columns.Clear();
            }
            /* JsonSerializerSettings settings = new JsonSerializerSettings();
             string jsongStr = JsonConvert.SerializeObject(result, settings);*/
            //转换成标准文档并遍历
            string bz = "";
            foreach (var item in result)
            {
                bz = item[0].ToString();
            }
            return bz;
        }

        private void GET_GXJHLB()
        {
            string text1 = comboBox1.Text;

            DateTime previoustime = DateTime.Parse(dateTimePicker1.Text).AddDays(-1);
            string previoustime2 = previoustime.ToString("yyyy-MM-dd");
            DateTime nexttime = DateTime.Parse(dateTimePicker1.Text).AddDays(1);
            string nexttime2 = nexttime.ToString("yyyy-MM-dd");
            if (text1 != null&&text1!="")
            {
                previoustime2 = "2000/1/11";
                nexttime2 = "3000/1/11";
            }
            previoustime2 = previoustime2 + " 23:59:59";
            nexttime2 = nexttime2 + " 00:00:01";
            K3CloudApi client = new K3CloudApi();
            //用于记录结果
            StringBuilder Info = new StringBuilder();
            //业务对象标识
            string formId = "SFC_OperationPlanning";//SFC_OperationPlanning
            //查询字段集合，即返回哪些数据，不能为空，根据不同业务单据填写不同的字段名，以下仅为示例
            string fieldKeys = "FMONumber,FProductId.FNumber,FMOQty,FProSpecification,FSeqPlanStartTime,F_SMGS_Text,FProductName,F_SMGS_BaseProperty";
            //请求参数，示例使用的是SDK提供的模板类，还可以使用字符串拼接等方式
            //"FMONumber like'%" + ZBLx + "%' and  FSeqPlanStartTime>'" + previoustime2 + "'and FSeqPlanStartTime<'" + nexttime2 + "' and (F_SMGS_Text='末工序FinalProcess' or F_SMGS_Text='首末工序First&FinalProcess')"
            var ZBLx = text1;
            var param = new QueryParam()
            {
                FormId = formId,
                FieldKeys = fieldKeys,
                FilterString = "FMONumber like'%" + ZBLx + "%' and  FSeqPlanStartTime>'" + previoustime2 + "'and FSeqPlanStartTime<'" + nexttime2 + "' and (F_SMGS_Text='末工序FinalProcess' or F_SMGS_Text='首末工序First&FinalProcess')",
                TopRowCount = 0,
                StartRow = 0,
                Limit = 120,
                OrderString = "FMONumber",
            };
            //调用接口
            var result = client.ExecuteBillQuery(param.ToJson());
            if (dataGridView1.Columns.Count != 0)
            {
                dataGridView1.Columns.Clear();
            }
            /* JsonSerializerSettings settings = new JsonSerializerSettings();
             string jsongStr = JsonConvert.SerializeObject(result, settings);*/
            //转换成标准文档并遍历
            int index = 1;
            DataTable dataTable = one.gyjh();
            foreach (var item in result)
            {
                dataTable.Rows.Add(index,item[0], item[1], item[2], item[3], item[4], item[5], item[6]);
                index++;
            }
            dataGridView1.DataSource = dataTable;
        }

        private DataTable GET_WUliao(string wlbm)
        {
            DateTime now = DateTime.Now;
            string currentDateTime = now.ToString("yyyy-MM-dd HH:mm:ss");
            K3CloudApi client = new K3CloudApi();
            //用于记录结果
            StringBuilder Info = new StringBuilder();
            //业务对象标识
            string formId = "BD_MATERIAL";
            //查询字段集合，即返回哪些数据，不能为空，根据不同业务单据填写不同的字段名，以下仅为示例
            string fieldKeys = "F_land_DBSL,FMnemonicCode,FName,F_land_MTSL";
            //请求参数，示例使用的是SDK提供的模板类，还可以使用字符串拼接等方式
            var ZBLx = wlbm;
            var param = new QueryParam()
            {
                FormId = formId,
                FieldKeys = fieldKeys,
                FilterString = "FNumber like'%" + ZBLx + "%'",
                TopRowCount = 0,
                StartRow = 0,
                Limit = 120,
                OrderString = "FNumber",
            };
            //调用接口
            var result = client.ExecuteBillQuery(param.ToJson());
            if (dataGridView1.Columns.Count != 0)
            {
                dataGridView1.Columns.Clear();
            }
            /* JsonSerializerSettings settings = new JsonSerializerSettings();
             string jsongStr = JsonConvert.SerializeObject(result, settings);*/
            //转换成标准文档并遍历
            DataTable dataTable = one.ERP_wlxx();
            foreach (var item in result)
            {
                dataTable.Rows.Add(item[0], item[1], item[2], item[3]);
            }
            return dataTable;
        }

        private void GET_CGDD()
        {
            string text1 = comboBox1.Text;


            DateTime previoustime = DateTime.Parse(dateTimePicker1.Text).AddDays(-1);
            string previoustime2 = previoustime.ToString("yyyy-MM-dd");
            DateTime nexttime = DateTime.Parse(dateTimePicker1.Text).AddDays(1);
            string nexttime2 = nexttime.ToString("yyyy-MM-dd");
            if (text1 != null)
            {
                previoustime2 = "2000/1/11";
                nexttime2 = "3000/1/11";
            }
            previoustime2 = previoustime2 + " 23:59:59";
            nexttime2 = nexttime2 + " 00:00:01";



            K3CloudApi client = new K3CloudApi();
            //用于记录结果
            StringBuilder Info = new StringBuilder();
            //业务对象标识
            string formId = "PRD_MO";
            //查询字段集合，即返回哪些数据，不能为空，根据不同业务单据填写不同的字段名，以下仅为示例
            string fieldKeys = "FBillNo,FMaterialId.FNumber,FQty,FSpecification,FStartDate";
            //请求参数，示例使用的是SDK提供的模板类，还可以使用字符串拼接等方式
            var ZBLx = comboBox1.Text;
            var param = new QueryParam()
            {
                FormId = formId,
                FieldKeys = fieldKeys,
                FilterString = "FBillNo like'%" + ZBLx + "%' and  FStartDate>'"+ previoustime2 + "'and FStartDate<'"+ nexttime2 + "'",
                TopRowCount = 0,
                StartRow = 0,
                Limit = 120,
                OrderString = "FBillNo",
            };
            //调用接口
            var result = client.ExecuteBillQuery(param.ToJson());
            if (dataGridView1.Columns.Count != 0)
            {
                dataGridView1.Columns.Clear();
            }
            /* JsonSerializerSettings settings = new JsonSerializerSettings();
             string jsongStr = JsonConvert.SerializeObject(result, settings);*/
            //转换成标准文档并遍历
            DataTable dataTable = one.ERP_cgdd();
            int index = 1;
            foreach (var item in result)
            {
                dataTable.Rows.Add(index,item[0], item[1], item[2], item[3], item[4]);
                index++;
            }
            
        }

        private void qqq()
        {
            DataGridViewImageColumn number = new DataGridViewImageColumn();
            number.HeaderText = "行号";
            number.Name = "number";
            dataGridView1.Columns.Add(number);

            DataGridViewTextBoxColumn FMONumber = new DataGridViewTextBoxColumn();
            FMONumber.HeaderText = "FMONumber";
            FMONumber.DataPropertyName = "FMONumber";
            dataGridView1.Columns.Add(FMONumber);


            DataGridViewTextBoxColumn FNumber = new DataGridViewTextBoxColumn();
            FNumber.HeaderText = "物料编码";
            FNumber.DataPropertyName = "FProductId.FNumber";
            dataGridView1.Columns.Add(FNumber);


            DataGridViewTextBoxColumn FMOQty = new DataGridViewTextBoxColumn();
            FMOQty.HeaderText = "数量";
            FMOQty.DataPropertyName = "FMOQty";
            dataGridView1.Columns.Add(FMOQty);


            DataGridViewTextBoxColumn FProSpecification = new DataGridViewTextBoxColumn();
            FProSpecification.HeaderText = "规格";
            FProSpecification.DataPropertyName = "FProSpecification";
            dataGridView1.Columns.Add(FProSpecification);


            DataGridViewTextBoxColumn FSeqPlanStartTime = new DataGridViewTextBoxColumn();
            FSeqPlanStartTime.HeaderText = "开工日期";
            FSeqPlanStartTime.DataPropertyName = "FStartDate";
            dataGridView1.Columns.Add(FSeqPlanStartTime);

            DataGridViewTextBoxColumn F_SMGS_Text = new DataGridViewTextBoxColumn();
            F_SMGS_Text.HeaderText = "首末工序";
            F_SMGS_Text.DataPropertyName = "F_SMGS_Text";
            dataGridView1.Columns.Add(F_SMGS_Text);

            DataGridViewTextBoxColumn FProductName = new DataGridViewTextBoxColumn();
            FProductName.HeaderText = "物料名称";
            FProductName.DataPropertyName = "FProductName";
            dataGridView1.Columns.Add(FProductName);

            DataGridViewTextBoxColumn F_SMGS_BaseProperty = new DataGridViewTextBoxColumn();
            F_SMGS_BaseProperty.HeaderText = "助记码";
            F_SMGS_BaseProperty.DataPropertyName = "F_SMGS_BaseProperty";
            dataGridView1.Columns.Add(F_SMGS_BaseProperty);

        }

        private void button3_Click(object sender, EventArgs e)
        {
            textBox3.Text = "";
            textBox4.Text = "";
            textBox6.Text = "";
            textBox7.Text = "";
            textBox8.Text = "";
            textBox2.Text = "";
            textBox5.Text = "";
            textBox11.Text = "";
            textBox9.Text = "";
            textBox10.Text = "";

        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            string num = textBox1.Text;
            foreach (DataGridViewRow data in dataGridView1.Rows)
            {
                string blbh = data.Cells[2].Value.ToString();
                string gg = data.Cells[4].Value.ToString();
                string riqi = data.Cells[5].Value.ToString();
                string sl = data.Cells[3].Value.ToString();
                string zjm = "";
                if (data.Cells[0].Value.ToString() == num)
                {
                    DataTable wlxx = GET_WUliao(data.Cells[2].Value.ToString());
                    foreach (DataRow data1 in wlxx.Rows)
                    {
                        zjm = data1[1].ToString();
                    }
                }
                if (zjm=="百库")
                {
                    panel1.Visible = false;
                    panel2.Visible = true;
                }
                else
                {
                    panel1.Visible = true;
                    panel2.Visible = false;
                }
            }
            GET_GXJHLB();
        }

        private void numericUpDown1_ValueChanged(object sender, EventArgs e)
        {

        }

        private void textBox12_KeyPress(object sender, KeyPressEventArgs e)
        {
            //允许数字、退格键和删除键
            if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar))
            {
                e.Handled = true;
            }

            // 如果允许小数，并且已有一个小数点，则阻止输入第二个小数点  
            if ((e.KeyChar == '.') && ((sender as TextBox).Text.IndexOf('.') > -1))
            {
                e.Handled = true;
            }
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        //private void printPreviewControl1_Click(object sender, EventArgs e)
        //{

        //}
        //private void PrintDocument1_PrintPage(object sender, PrintPageEventArgs e)
        //{
        //    string filePath = "path_to_your_text_file.txt"; // 确保这个路径在打印之前已经被设置  
        //    string textToPrint = File.ReadAllText(filePath);

        //    // 假设你想要打印的内容适应打印页面的宽度  
        //    // 你可以使用StringFormat来设置文本的对齐方式和换行  
        //    StringFormat format = new StringFormat
        //    {
        //        Alignment = StringAlignment.Near,
        //        LineAlignment = StringAlignment.Center,
        //        Trimming = StringTrimming.EllipsisCharacter
        //    };

        //    // 设置字体和边距（可选）  
        //    Font printFont = new Font("Arial", 10);
        //    float linesPerPage = 0;
        //    float yPos = 0;
        //    int count = 0;
        //    float leftMargin = e.MarginBounds.Left;
        //    float topMargin = e.MarginBounds.Top;
        //    string line = null;

        //    // 计算每页可以打印的行数  
        //    linesPerPage = e.MarginBounds.Height / printFont.GetHeight(e.Graphics);

        //    // 打印每一行文本  
        //    using (StringReader sr = new StringReader(textToPrint))
        //    {
        //        while (count < linesPerPage && ((line = sr.ReadLine()) != null))
        //        {
        //            yPos = topMargin + (count * printFont.GetHeight(e.Graphics));
        //            e.Graphics.DrawString(line, printFont, Brushes.Black, leftMargin, yPos, format);
        //            count++;
        //        }

        //        // 如果还有更多的文本需要打印，则设置HasMorePages为true  
        //        if (line != null)
        //            e.HasMorePages = true;
        //        else
        //            e.HasMorePages = false;
        //    }
        //}
    }
}
